<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;

/**
 * App\Model\Setting
 *
 * @mixin \Eloquent
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Setting newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Setting newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Setting query()
 * @property int $id
 * @property string $name 名称
 * @property string $describe 描述
 * @property string $value 值
 * @property string $addenda 补充
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Setting whereAddenda($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Setting whereDescribe($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Setting whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Setting whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Setting whereValue($value)
 */
class Setting extends Model
{
    protected $table = 'setting';

    public static function getValue($name)
    {
        $settings = Cache::remember('setting', 1440, function (){
            return Setting::select('name', 'value', 'addenda')->get()->keyBy('name');
        });
        return isset($settings[$name])?$settings[$name]:[];
    }
}
